#!/bin/bash
# 添加SystemConfiguration到现有备份的脚本

if [ "$EUID" -ne 0 ]; then
    echo "此脚本需要管理员权限，请使用: sudo ./add_system_config.sh [备份目录]"
    exit 1
fi

# 检查参数
if [ -z "$1" ]; then
    echo "使用方法: sudo ./add_system_config.sh [备份目录路径]"
    echo "例如: sudo ./add_system_config.sh '/Users/m/Downloads/netWorkBackUp/netWork-backup-250921_215307'"
    exit 1
fi

BACKUP_DIR="$1"

if [ ! -d "$BACKUP_DIR" ]; then
    echo "错误: 备份目录 '$BACKUP_DIR' 不存在"
    exit 1
fi

echo "添加SystemConfiguration到备份目录: $BACKUP_DIR"

# 备份SystemConfiguration目录
if [ -d "/Library/Preferences/SystemConfiguration" ]; then
    echo "正在备份SystemConfiguration目录..."
    cp -r "/Library/Preferences/SystemConfiguration" "$BACKUP_DIR/"
    chown -R $(logname) "$BACKUP_DIR/SystemConfiguration" 2>/dev/null
    echo "✅ SystemConfiguration目录已添加到备份"
    
    # 统计文件数量
    config_count=$(ls "$BACKUP_DIR/SystemConfiguration" 2>/dev/null | wc -l)
    echo "   包含 $config_count 个配置文件"
else
    echo "❌ SystemConfiguration目录不存在"
    exit 1
fi

# 备份其他系统配置
echo "备份其他系统配置..."
[ -f "/etc/ppp/options" ] && cp /etc/ppp/options "$BACKUP_DIR/ppp_options.txt" 2>/dev/null && echo "✅ PPP配置已备份"
[ -f "/etc/krb5.conf" ] && cp /etc/krb5.conf "$BACKUP_DIR/krb5_conf.txt" 2>/dev/null && echo "✅ Kerberos配置已备份"
[ -f "/etc/ssh/ssh_config" ] && cp /etc/ssh/ssh_config "$BACKUP_DIR/ssh_config.txt" 2>/dev/null && echo "✅ SSH配置已备份"

echo ""
echo "✅ 系统配置添加完成！"
echo "现在可以运行验证脚本检查备份完整性:"
echo "cd '$BACKUP_DIR' && ./verify_backup.sh"
